package com.hellowx_ssm.aop.aspectj;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

/**
 * Created by IntelliJ IDEA.
 *
 * @author MagicMushroom
 * @date 2021/6/17
 */
/*
    xml方式
    额外功能
    public class Around implements MethodInterceptor{
        public Object invoke(MethodInvocation invocation){
            System.out.println("before")
            Object ret = invocation.proceed();
            System.out.println("after")
            return ret;
        }
    }

    <bean id="around" class="com.xx.Around"/>

    配置aop
    <aop:config>
        配置切入点表达式
        <aop:pointcut id ="pc" expression="execution(* *.*(..))"/>
        组装
        <aop:advisor pointcut-ref="pc" advice-ref="around"/>
    </aop:config>
 */

@Aspect
public class MyAspectj {
    @Around("args(com.hellowx_ssm.aop.aspectj.User)")
    public Object around(ProceedingJoinPoint joinPoint){
        System.out.println("开启事务");
        Object ret = null;
        try {
            ret = joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        System.out.println("提交事务");
        return ret;
    }
}
